<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Rep\ProductRep;
use Illuminate\Http\Request;

class Product extends Controller
{
    //产品管理
    protected $rep;

    public function __construct(Request $request)
    {
        $this->rep = new ProductRep();
    }

    /**
     * 获取产品列表
     * product_name
     * color_id
     *
     */
    public function getProductList(Request $request){
        $params = $request->all();
        $data = $this->rep->getProductListRep($params);
        return re(0,$data,'success');
    }

    /**
     * 添加产品
     * id
     * product_name
     * color_ids      array[]
     */
    public function createProduct(Request $request){
        //$params = $request->getContent();
        $params = $request->all();
        $data = $this->rep->createProductRep($params);
        return re(0,$data['data'],$data['msg']);
    }

    /**删除**/
    public function delProduct(Request $request){
        $params = $request->all();
        $data = $this->rep->delProductRep($params);
        return re(0,$data,'success');
    }

    /**
     * 获取产品的关联型号列表
     */
    public function getModelNumberByProduct(Request $request){
        $product_id = $request->input('product_id');
        $data = $this->rep->getModelNumberByProductRep($product_id);
        return re(0,$data,'success');
    }

    /**
     * 获取产品颜色列表
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getProductColorList(Request $request){
        $params = $request->all();
        $data = $this->rep->getProductColorListRep($params);
        return re(0,$data,'success');
    }

    /**
     * 添加产品颜色
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addProductColor(Request $request){
        //$params = $request->getContent();
        $params = $request->all();
        $data = $this->rep->addProductColorRep($params);
        return re(0);
    }

    /**
     * 删除产品颜色
     * @param Request $request
     */
    public function delProductColor(Request $request){
        $params = $request->all();
        $data = $this->rep->delProductColorRep($params);
        return re(0);
    }

    /**
     * 获取产品工序
     */
    public function getProductJobTypeList(Request $request){
        $params = $request->all();
        $data = $this->rep->getProductJobTypeListByProductId($params);
        return re(0,$data,'success');
    }


    /**
     * 添加产品工种
     */
    public function addProductJobType(Request $request){
        $params = $request->all();
        $data = $this->rep->addProductJobTypeRep($params);
        return re(0);
    }


    /**
     * 设置工序
     */
//    public function setProductJobType(Request $request){
//        $params = $request->all();
//        $data = $this->rep->setProductJobTypeRep($params);
//        return re(0);
//    }

    /**
     * 移除产品工种关联
     */
    public function delProductJobType(Request $request){
        $params = $request->all();
        $data = $this->rep->delProductJobTypeRep($params);
        return re(0);
    }

    /**
     * 设置产品工种排序
     * @param Request $request
     * $product_id  产品id
     * $sort_info   排序详情
     */
    public function setProductJobTypeSort(Request $request){
        $params = $request->all();
        $data = $this->rep->setProductJobTypeSortRep($params);
        return re($data['code'],$data['data'],$data['msg']);
    }

    /**
     * 获取产品工种排序
     * @param Request $request
     */
    public function getProductJobTypeSort(Request $request){
        $params = $request->all();
        $data = $this->rep->getProductJobTypeSortRep($params);
        return re(0,$data,'success');
    }

}
